home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / gui / gtlayout.lha / Source / LT_Rebuild.c < prev    next >
C/C++ Source or Header  |  1999-01-03  |  8KB  |  377 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1999 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <stdarg.h>
  17.  
  18. /*****************************************************************************/
  19.  
  20. #include "Assert.h"
  21.  
  22. /*****************************************************************************/
  23.  
  24.  
  25. VOID
  26. LTP_Erase(LayoutHandle *Handle)
  27. {
  28.     struct Window *Window = Handle->Window;
  29.  
  30.     EraseRect(&Handle->RPort,Window->BorderLeft,Window->BorderTop,Window->Width - (Window->BorderRight + 1),Window->Height - (Window->BorderBottom + 1));
  31. }
  32.  
  33.  
  34. /*****************************************************************************/
  35.  
  36.  
  37. /****** gtlayout.library/LT_RebuildTagList ******************************************
  38. *
  39. *   NAME
  40. *    LT_RebuildTagList -- Rebuild the user interface after modifying it.
  41. *
  42. *   SYNOPSIS
  43. *    Success = LT_RebuildTagList(Handle,Clear,TagList);
  44. *       D0                         A0    D0     A1
  45. *
  46. *    BOOL LT_RebuildTagList(LayoutHandle *,BOOL,struct TagItem *);
  47. *
  48. *    Success = LT_RebuildTags(Handle,Clear,...);
  49. *
  50. *    BOOL LT_RebuildTags(LayoutHandle *,BOOL,...);
  51. *
  52. *   FUNCTION
  53. *    Certain aspects of the user interface can be changed at run time,
  54. *    such as button labels. This routine will let you rebuild the interface
  55. *    based upon the data supplied at creation time and your subsequent
  56. *    changes. Before you make any vital changes, it is recommended to
  57. *    lock the window using LT_LockWindow() in order to avoid clashes
  58. *    with the Intuition and GadTools subsystems.
  59. *
  60. *   INPUTS
  61. *    Handle - Pointer to LayoutHandle structure.
  62. *
  63. *    Clear - Pass in TRUE if you wish to have the window contents
  64. *        cleared before they are rebuild. This will introduce
  65. *        some visual hashing.
  66. *
  67. *    TagList - Attributes controlling the layout process.
  68. *
  69. *
  70. *    Valid tags include:
  71. *
  72. *    LAWN_Bounds (struct IBox *) - Boundaries in which the window
  73. *        should be centered.
  74. *
  75. *    LAWN_ExtraWidth (LONG) - Extra space to add to the window
  76. *        width.
  77. *
  78. *    LAWN_ExtraHeight (LONG) - Extra height to add to the window
  79. *        height.
  80. *
  81. *   RESULT
  82. *    Success - TRUE indicates that the interface was rebuilt,
  83. *        FALSE indicates trouble; it is recommended to
  84. *        call LT_DeleteHandle() on your LayoutHandle as
  85. *        soon as possible as the previous operation may
  86. *        have left the user interface in an inoperable
  87. *        state.
  88. *
  89. ******************************************************************************
  90. *
  91. */
  92.  
  93. BOOL LIBENT
  94. LT_RebuildTagList(REG(a0) LayoutHandle *handle,REG(d0) BOOL clear,REG(a1) struct TagItem *TagParams)
  95. {
  96.     struct TagItem    *item,
  97.                     *list;
  98.     struct IBox        *bounds = NULL;
  99.     LONG             RightEdge,
  100.                      BottomEdge;
  101.  
  102.     list = TagParams;
  103.  
  104.     while(item = NextTagItem(&list))
  105.     {
  106.         switch(item->ti_Tag)
  107.         {
  108.             case LAWN_Bounds:
  109.  
  110.                 bounds = (struct IBox *)item->ti_Data;
  111.                 break;
  112.         }
  113.     }
  114.  
  115.     if(handle)
  116.     {
  117.         struct Gadget    *gadget,
  118.                         *next;
  119.         ObjectNode        *node;
  120.         LONG             left,top;
  121.         struct IBox         newBounds;
  122.         struct Image    **ImagePtr;
  123.  
  124.         if(!handle->SizeVerified)
  125.         {
  126.             LTP_StripGadgets(handle,handle->List);
  127.  
  128.             #ifdef DO_BOOPSI_KIND
  129.             {
  130.                 LTP_StripGadgets(handle,(struct Gadget *)handle->BOOPSIList);
  131.             }
  132.             #endif    /* DO_BOOPSI_KIND */
  133.         }
  134.         gadget = handle->List;
  135.  
  136.         while(gadget)
  137.         {
  138.             if(GETOBJECT(gadget,node))
  139.             {
  140.                 LTP_PutStorage(node);
  141.  
  142.                 ImagePtr = NULL;
  143.  
  144.                 switch(node->Type)
  145.                 {
  146.                     #ifdef DO_GAUGE_KIND
  147.                     {
  148.                         case GAUGE_KIND:
  149.  
  150.                             node->Special.Gauge.LastPercentage = -1;
  151.                             break;
  152.                     }
  153.                     #endif    /* DO_GAUGE_KIND */
  154.  
  155.                     case BUTTON_KIND:
  156.  
  157.                         ImagePtr = &node->Special.Button.ButtonImage;
  158.                         break;
  159.  
  160.                     case PICKER_KIND:
  161.  
  162.                         ImagePtr = &node->Special.Picker.Image;
  163.                         break;
  164.  
  165.                     case TAPEDECK_KIND:
  166.  
  167.                         ImagePtr = &node->Special.TapeDeck.ButtonImage;
  168.                         break;
  169.  
  170.                     case INCREMENTER_KIND:
  171.  
  172.                         ImagePtr = &node->Special.Incrementer.Image;
  173.                         break;
  174.  
  175.                     case STRING_KIND:
  176.                     case FRACTION_KIND:
  177.  
  178.                         if(!node->Special.String.Backup)
  179.                             node->Special.String.Backup = (STRPTR)LTP_Alloc(handle,node->Special.String.MaxChars + 1);
  180.  
  181.                         if(node->Special.String.Backup)
  182.                         {
  183.                             strcpy(node->Special.String.Backup,((struct StringInfo *)gadget->SpecialInfo)->Buffer);
  184.  
  185.                             node->Special.String.String = node->Special.String.Backup;
  186.                         }
  187.  
  188.                         node->Special.String.Picker = NULL;
  189.  
  190.                         node->Special.String.LeftIncrementer    = NULL;
  191.                         node->Special.String.RightIncrementer    = NULL;
  192.  
  193.                         break;
  194.  
  195.                     case TEXT_KIND:
  196.  
  197.                         node->Special.Text.Picker = NULL;
  198.                         break;
  199.  
  200.                     case INTEGER_KIND:
  201.  
  202.                         node->Special.Integer.LeftIncrementer    = NULL;
  203.                         node->Special.Integer.RightIncrementer    = NULL;
  204.  
  205.                         break;
  206.                 }
  207.  
  208.                 if(ImagePtr)
  209.                 {
  210.                     DisposeObject(*ImagePtr);
  211.  
  212.                     *ImagePtr = NULL;
  213.                 }
  214.  
  215.                 node->Host = NULL;
  216.             }
  217.  
  218.             gadget = gadget->NextGadget;
  219.         }
  220.  
  221.         FreeGadgets(handle->List);
  222.  
  223.         handle->List = NULL;
  224.  
  225.         #ifdef DO_BOOPSI_KIND
  226.         {
  227.             gadget = (struct Gadget *)handle->BOOPSIList;
  228.  
  229.             while(gadget)
  230.             {
  231.                 next = gadget->NextGadget;
  232.  
  233.                 if(GETOBJECT(gadget,node))
  234.                 {
  235.                     switch(node->Type)
  236.                     {
  237.                         case TEXTEDIT_KIND:
  238.                         {
  239.                             STRPTR string;
  240.  
  241.                             GetAttr(STRINGA_Buffer,gadget,(ULONG *)&string);
  242.  
  243.                             if(node->Special.TextEdit.Backup != NULL)
  244.                                 LTP_Free(handle,node->Special.TextEdit.Backup,strlen(node->Special.TextEdit.Backup)+1);
  245.  
  246.                             node->Special.TextEdit.Backup = (STRPTR)LTP_Alloc(handle,strlen(string)+1);
  247.                             if(node->Special.TextEdit.Backup != NULL)
  248.                             {
  249.                                 strcpy(node->Special.TextEdit.Backup,string);
  250.     
  251.                                 node->Special.TextEdit.String = node->Special.TextEdit.Backup;
  252.                             }
  253.  
  254.                             break;
  255.                         }
  256.                     }
  257.  
  258.                     DisposeObject(gadget);
  259.  
  260.                     if(node->Type == BOOPSI_KIND)
  261.                     {
  262.                         if(node->Special.BOOPSI.ClassBase)
  263.                         {
  264.                             CloseLibrary(node->Special.BOOPSI.ClassBase);
  265.  
  266.                             node->Special.BOOPSI.ClassBase = NULL;
  267.                         }
  268.                     }
  269.  
  270.                     node->Host = NULL;
  271.                 }
  272.  
  273.                 gadget = next;
  274.             }
  275.  
  276.             handle->BOOPSIList = NULL;
  277.             handle->BOOPSIPrevious = NULL;
  278.         }
  279.         #endif    /* DO_BOOPSI_KIND */
  280.  
  281.         LTP_Free(handle,handle->GadgetArray,sizeof(struct Gadget *) * handle->Count);
  282.  
  283.         handle->GadgetArray = NULL;
  284.  
  285.         handle->Count = handle->Index = 0;
  286.  
  287.         LTP_ResetGroups(handle->TopGroup);
  288.  
  289.         if(!bounds)
  290.         {
  291.             bounds = &newBounds;
  292.  
  293.             newBounds.Left        = 0;
  294.             newBounds.Top        = 0;
  295.             newBounds.Width        = handle->Window->Width;
  296.             newBounds.Height    = handle->Window->Height;
  297.         }
  298.  
  299.         left        = handle->Window->BorderLeft;
  300.         top            = handle->Window->BorderTop;
  301.         RightEdge    = handle->Window->BorderRight;
  302.         BottomEdge    = handle->Window->BorderBottom;
  303.  
  304.         if(!handle->FlushLeft)
  305.         {
  306.             left        += handle->InterWidth;
  307.             RightEdge    += handle->InterWidth;
  308.         }
  309.  
  310.         if(!handle->FlushTop)
  311.         {
  312.             top            += handle->InterHeight;
  313.             BottomEdge    += handle->InterHeight;
  314.         }
  315.  
  316.         LTP_CreateGadgets(handle,bounds,left,top,left + RightEdge,top + BottomEdge);
  317.  
  318.         if(handle->Failed)
  319.         {
  320.             handle->SizeVerified = FALSE;
  321.  
  322.             LTP_Erase(handle);
  323.  
  324.             RefreshWindowFrame(handle->Window);
  325.  
  326.             return(FALSE);
  327.         }
  328.  
  329.         if(clear)
  330.         {
  331.             LTP_Erase(handle);
  332.  
  333.             if(!handle->SizeVerified)
  334.                 RefreshWindowFrame(handle->Window);
  335.         }
  336.  
  337.         handle->SizeVerified = FALSE;
  338.  
  339.         LTP_AddGadgets(handle);
  340.  
  341.         LTP_SelectInitialActiveGadget(handle);
  342.  
  343.         return(TRUE);
  344.     }
  345.     else
  346.         return(FALSE);
  347. }
  348.  
  349.  
  350. /*****************************************************************************/
  351.  
  352.  
  353. BOOL
  354. LT_RebuildTags(LayoutHandle *Handle,BOOL Clear,...)
  355. {
  356.     va_list VarArgs;
  357.     BOOL    Result;
  358.  
  359.     va_start(VarArgs,Clear);
  360.     Result = LT_RebuildTagList(Handle,Clear,(struct TagItem *)VarArgs);
  361.     va_end(VarArgs);
  362.  
  363.     return(Result);
  364. }
  365.  
  366.  
  367. /*****************************************************************************/
  368.  
  369.  
  370. BOOL LIBENT
  371. LT_Rebuild(REG(a0) LayoutHandle *handle,REG(a1) struct IBox *bounds,REG(a2) LONG extraWidth,REG(d0) LONG extraHeight,REG(d1) BOOL clear)
  372. {
  373.     return(LT_RebuildTags(handle,clear,
  374.         LAWN_Bounds,bounds,
  375.     TAG_DONE));
  376. }
  377.